import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat/common/widget/widgets.dart';
import 'package:get/get.dart';
import 'logic.dart';

class MessagePage extends GetView<MessageLogic> {
  const MessagePage({super.key});

  @override
  Widget build(BuildContext context) {
    return _buildEasyRefresh();
  }

  EasyRefresh _buildEasyRefresh() {
    return EasyRefresh.builder(
      header: CustomClassic().getHeader(),
      footer: CustomClassic().getFooter(),
      onRefresh: () async {
        await Future.delayed(const Duration(seconds: 2));
      },
      childBuilder: (context, physics) {
        return _buildChatList(physics);
      },
    );
  }

  ListView _buildChatList(ScrollPhysics physics) {
    return ListView.separated(
      physics: physics,
      itemCount: 20,
      itemBuilder: (BuildContext context, int index) {
        return const ChatItem();
      },
      separatorBuilder: (BuildContext context, int index) {
        return const Divider(height: 1);
      },
    );
  }
}
